package org.beetl.support;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

public class JdbcConfigDataSource implements javax.sql.DataSource {

 JdbcConfig jdbcConfig;

 public JdbcConfigDataSource(JdbcConfig jdbcConfig) {
  super();
  this.jdbcConfig = jdbcConfig;
 }

 public PrintWriter getLogWriter() throws SQLException {
  return null;
 }

 public void setLogWriter(PrintWriter out) throws SQLException {

 }

 public void setLoginTimeout(int seconds) throws SQLException {

 }

 public int getLoginTimeout() throws SQLException {
  return 0;
 }

 public Logger getParentLogger() throws SQLFeatureNotSupportedException {
  return null;
 }

 
 public <T> T unwrap(Class<T> iface) throws SQLException {
  return null;
 }

 
 public boolean isWrapperFor(Class<?> iface) throws SQLException {
  return false;
 }

 public Connection getConnection() throws SQLException {
  Connection conn = null;
  try {
   conn = DriverManager.getConnection(this.jdbcConfig.getUrl(), this.jdbcConfig.getUser(), this.jdbcConfig.getPassword());
  } catch (SQLException e) {
   LogSupport.error("getConnection url:{} user:{} password:{} exception:{}",
     new Object[] { this.jdbcConfig.getUrl(), this.jdbcConfig.getUser(), this.jdbcConfig.getPassword(), e });
   throw new RuntimeException(e);
  }
  return conn;
 }

 public Connection getConnection(String username, String password) throws SQLException {
  return this.getConnection();
 }

}
